<script type="text/javascript" src="/js/fileupload.js"></script>
<script type="text/javascript">
function reloadFilesList() {
    $.get("/files/getinnerlist?group=<?php echo $group->getId() ?>", '', displayFiles, 'text');
}

function uploadFormRef() {
	return '#upload-form';
}
</script>
<?php slot('studyGroupsNav', 'active') ?>
<div id="wrapper" class="courses">
	<?php include_partial('global/systemMessages', array('form' => isset($form) ? $form : null)) ?>
	<div id="content">
	<!--  
		<div id="location-bar">
			<form action="" method="post">
				<fieldset>
					<select>
						<option>Harvard</option>
					</select>
				</fieldset>
			</form>
			<ul class="breadcrumbs">
				<li class="first"><a href="#">Groups</a> &raquo;</li>
				<li><?php echo $group->getName() ?></li>
			</ul>
		</div>
	-->
		<div id="main">
			<div class="main-heading">
				<h1><?php echo $group->getName() ?></h1>
			</div>

			<?php include_partial('subnav', array('group_id' => $group->getId())) ?>

			<?php include_component('groups','taskheading', array('group'=>$group));?>


			<form id="group-tasks" method="post" action="">
			<fieldset>

				<?php 
					include_component('tasks','latetasks', array('group_id'=>$group->getId()));
				?>
				<?php include_component('tasks','recentcomptasks', array('limit'=>10, 'group_id'=>$group->getId()));?>
				<?php include_component('tasks','usertasks', array('group_id'=>$group->getId()));?>

			</fieldset>
			
			
			<p class="actions">
				<!--<a href="#">View and Manage Tasks and Lists &raquo;</a>-->
			</p>
			
			</form>


			<div class="filter-links with-icon" id="filter_links">
				<ul class="book">
					<li id="tab_1">
						<?php echo link_to('Recent Notes', 'notes/index/?group_id='.$group->getId().'&isAjax=true', 'onclick="displayTabContent(1)"')?>
					</li>
					
					<!--
					<li id="tab_2" >
							<?php echo link_to('Recent Annotations', 'notes/id/'.$group->getId(), 'onclick="displayTabContent(2)"')?>
					</li>
					<li id="tab_3" >
							<?php echo link_to('Recent Readings', 'notes/id/'.$group->getId(), 'onclick="displayTabContent(3)"')?>
					</li>
					-->
					
				</ul>
			</div>


		</div>



		<div id="sidebar">

		<!--
			
			<div class="module messages">
				<h3 class="gradient dark with-message">Message Center</h3>
				<div class="inner">
					<div class="empty">
						<p>There are no group messages.</p>
						<p><a href="#">Create a New Message &raquo;</a></p>
					</div>
				</div>
			</div>
		-->
			<?php include_component('messages','groupsidebar', array('group'=>$group))?>
				
			<?php include_component('group_members', 'pending', array('group_id' => $group->getId()))?>
			<?php include_component('group_members', 'list', array('group_id' => $group->getId()))?>
			<?php include_component('files', 'list', array('group_id' => $group->getId()))?>
		</div>
	</div>
</div>



<script>

/**
*display the full list of completed tasks for this group
*/
function viewCompletedTasks(){
	
	$.get( $('.view-comp-tasks').attr('href'), {},
			function(data) {
				$('.completed-tasks').replaceWith(data);
				$('.completed-tasks').hide();
				$('.completed-tasks').slideDown(1000);
				
				bindTaskLink();
			}
	);
	return false;
}


/**
* Binds an ajax request to mark the task as completed or still open to all check boxes
*/
function bindUpdateStatus() {
	$('.complete_task_box').click(function(){
		var id = $(this).val();
		var status = $(this).attr('checked') ? <?php echo TaskPeer::COMPLETED ?> : <?php echo TaskPeer::OPEN ?>;
		$.ajax({
			type: "POST",
			url: "<?php echo url_for('tasks/updateStatus')?>",
			data: "id=" + id + '&status=' + status,
			beforeSend: function(xhr) {
				$('#task_loading_' + id).show();		// display the loading image
				$('#status_update_' + id).hide();		// hide the status area
			},
			success: function(msg) {
				$('#task_loading_' + id).hide();		// display the loading image
				$('#status_update_' + id).show();		// hide the status area
				$('#status_update_' + id).html(msg);
			}
		});	
	});
}
	

/**
*  Disable task link
*/
function bindTaskLink() {
	$('.view-comp-tasks').click(function(){
		return false;
	});
}



/**
*  show tab content when clicked
*/
function displayTabContent(tab) {
	//redistribute css
	$('.book > li').attr('class', '');
	$('#tab_'+tab).attr('class', 'current');

	//get the href for the clicked tab
	url = $('#tab_'+tab+' > a').attr('href');

	
	//redisplay content
	$.get( url, {},
			function(data) {
				$('.actions').eq(1).remove();
				$('#filter_links').after(data);

				bindShare();
			}
			
	
	);
	return false;
	
}


/**
*  Bind tab links
*/
function bindTabs() {
	$('.book > li').click(function(){
		return false;
	});
}


/**
*  Bind note sharing capability
*/
function bindShare(){
	$(".share").click(function(){
		var options = {
			data: {state: this.id},
			success:  function(response){ alert(response)},
		}
		$("#" + this.name).ajaxSubmit(options);	
	});
	
	$(".share").confirm({
		timeout:3000,
		dialogShow:'fadeIn',
		dialogSpeed:'slow',
		msg: "Change course materials permissions?",
		buttons: {
			wrapper:'<button></button>',
			separator:'  '
	  }  

		
	});
	
}




// bind an ajax function to all check boxes when the document loads
$(document).ready(function(){

	bindUpdateStatus();
	bindTaskLink();
	bindTabs();
	displayTabContent(1);
});





</script>
